package test.monitor;

import ar.uba.dc.sistemas.monitorRW.AlternatingReadersWriters;
import ar.uba.dc.sistemas.monitorRW.MultipleReadersWritersMonitor;
import ar.uba.dc.sistemas.monitorRW.ReadersPreferred;
import ar.uba.dc.sistemas.monitorRW.SingleReaderWriter;
import ar.uba.dc.sistemas.monitorRW.TakeANumberMonitor;
import ar.uba.dc.sistemas.monitorRW.WritersPreferred;


public class MonitorTestSuite{

	public static void testSingleReaderWriterMonitor(){ 
		
		Integer objCompartido = new Integer(0);
		MultipleReadersWritersMonitor monitor = new SingleReaderWriter();
		Thread writerThread = new Thread(new Writer(monitor, objCompartido, "escritor 1"));
		Thread readerThread = new Thread(new Reader(monitor, objCompartido, "lector 1"));
		writerThread.start();
		readerThread.start();
	}

	public static void testAlternatingReadersWritersMonitor(){ 
		
		Integer objCompartido = new Integer(0);
		MultipleReadersWritersMonitor monitor = new AlternatingReadersWriters();
		Thread writerThread1 = new Thread(new Writer(monitor, objCompartido, "escritor 1"));
		Thread readerThread1 = new Thread(new Reader(monitor, objCompartido, "lector 1"));
		Thread writerThread2 = new Thread(new Writer(monitor, objCompartido, "escritor 2"));
		Thread readerThread2 = new Thread(new Reader(monitor, objCompartido, "lector 2"));
		writerThread1.start();
		readerThread1.start();
		writerThread2.start();
		readerThread2.start();
	}
	
	public static void testReadersPreferredMonitor(){ 
		
		Integer objCompartido = new Integer(0);
		MultipleReadersWritersMonitor monitor = new ReadersPreferred();
		Thread writerThread1 = new Thread(new Writer(monitor, objCompartido, "escritor 1"));
		Thread writerThread2 = new Thread(new Writer(monitor, objCompartido, "escritor 2"));
		Thread readerThread1 = new Thread(new Reader(monitor, objCompartido, "lector 1"));
		Thread readerThread2 = new Thread(new Reader(monitor, objCompartido, "lector 2"));
		Thread readerThread3 = new Thread(new Reader(monitor, objCompartido, "lector 3"));
		writerThread1.start();
		writerThread2.start();
		readerThread1.start();
		readerThread2.start();
		readerThread3.start();
	}
	
	public static void testTakeANumberMonitorMonitor(){ 
		
		Integer objCompartido = new Integer(0);
		MultipleReadersWritersMonitor monitor = new TakeANumberMonitor();
		Thread writerThread = new Thread(new Writer(monitor, objCompartido, "escritor 1"));
		Thread readerThread = new Thread(new Reader(monitor, objCompartido, "lector 1"));
		writerThread.start();
		readerThread.start();
	}
	
	public static void testWritersPreferredMonitor(){ 
		
		Integer objCompartido = new Integer(0);
		MultipleReadersWritersMonitor monitor = new WritersPreferred();
		Thread writerThread = new Thread(new Writer(monitor, objCompartido, "escritor 1"));
		Thread readerThread = new Thread(new Reader(monitor, objCompartido, "lector 1"));
		writerThread.start();
		readerThread.start();
	}
}
